package leetcode;

import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class code101 {

    public static class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;
        TreeNode(int x) { val = x; }
        TreeNode(int x, TreeNode left, TreeNode right) {
            this.val = x;
            this.left = left;
            this.right = right;
        }
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] arrayA = new int[n];
        for (int i = 0; i < n; i++) {
            arrayA[i] = scanner.nextInt();
        }
        TreeNode treeNode = buildTree(arrayA);

        boolean symmetric = isSymmetric(treeNode);
        System.out.println(symmetric);

    }

    public static boolean isSymmetric(TreeNode root) {
        return check(root.left,root.right);
    }

    public static  boolean check(TreeNode p , TreeNode q){
        if (p==null&&q==null){
            return true;
        }
        if (p==null||q==null){
            return false;
        }
        return p.val==q.val&&check(p.left,q.right)&&check(p.right,q.left);
    }


    public static TreeNode buildTree(int[] arry){
        if(arry==null||arry.length==0){
            return null;
        }
        TreeNode root = new TreeNode(arry[0]);
        Queue<TreeNode> queue = new LinkedList<>();
        queue.offer(root);
        int i = 1;
        while(!queue.isEmpty()&&i<arry.length){
            TreeNode currentNode = queue.poll();
            if(i<arry.length){
                currentNode.left = new TreeNode(arry[i]);
                queue.offer(currentNode.left);
            }
            i++;
        }
        return root;
    }


}
